package com.gxa.controller.shezhicontroller;

import com.gxa.common.R;
import com.gxa.pojo.User;
import com.gxa.pojo.UserQuanXian;
import com.gxa.service.shezhiservice.QuanXianService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author weishen
 */
@RestController
@RequestMapping("/QuanXian")
@Api(value = "权限管理" , tags = "权限数据接口API")
@RequiresPermissions("权限设置")
public class QuanXianController {


    @Autowired
    QuanXianService quanXianService;

    @Autowired
    public R r;

    @GetMapping("/selectAllUserAndQuanXianForPage")
    @ApiOperation(value = "查询用户与权限信息接口",notes = "提供页码和每页显示数",httpMethod = "get",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page",value = "当前页码数",required = true,dataType = "int",paramType = "query"),
            @ApiImplicitParam(name = "size",value = "每页显示数",required = true,dataType = "int",paramType = "query"),

    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectAllUserAndQuanXianForPage(@RequestParam int page, @RequestParam int size)
    {
        return quanXianService.selectAllUserAndQuanXianForPage(page, size);
    }
    @PostMapping("/updatePasswordById")
    @ApiOperation(value="重置密码接口",notes = "提供id和密码",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="主键",required = true,dataType = "int"),
            @ApiImplicitParam(name="password",value="密码",required = true,dataType = "String")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updatePasswordById(@RequestParam int id,@RequestParam String password)
    {
        return quanXianService.updatePasswordById(id,password);
    }
    @PostMapping("/insertUser")
    @ApiOperation(value="新增用户接口",notes="提供用户信息",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R insertUser(@RequestBody User user)
    {
        return quanXianService.insertUser(user);
    }


    @GetMapping("/selectAllQuanXian")
    @ApiOperation(value = "查询功能权限接口",notes = "提供页码和每页显示数",httpMethod = "get",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R selectAllQuanXian()
    {
       return quanXianService.selectAllQuanXian();
    }
    @PostMapping("/updateQuanXianById")
    @ApiOperation(value="修改权限接口",notes = "提供客户id和权限id",httpMethod = "post",response = R.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateQuanXianById(@RequestBody ArrayList<UserQuanXian> list)
    {
        return quanXianService.updateQuanXianById(list);
    }

    @PostMapping("/updateQuanXianForLogin")
    @ApiOperation(value="修改登录权限接口",notes = "提供id和登录权限状态",httpMethod = "post",response = R.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name="id",value="主键",required = true,dataType = "int"),
            @ApiImplicitParam(name="quanXianLogin",value="登录权限状态 0:禁用 1:启用",required = true,dataType = "int")
    })
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=404,message="找不到页面"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    public R updateQuanXianForLogin(@RequestParam int id,@RequestParam int quanXianLogin)
    {
        return quanXianService.updateQuanXianLogin(id,quanXianLogin);
    }

}
